/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package testutil;

import algorithm.ObjectiveFunction;
import algorithm.Phenotype;
import simple.DoubleArrayPhenotype;

/** Expect multiple minima per dimension.
 * There is also a slight slope towards 0. The true maximum is at 0 (in all dimensions)
 *
 * @author vermaak
 */
public class MultiMinimumTestObjectiveFunctionSingleDimension implements ObjectiveFunction {

    private final int index;

    public MultiMinimumTestObjectiveFunctionSingleDimension(int index) {
        this.index = index;
    }

    public double calculateFitness(Phenotype phenotype) {
        double[] values = ((DoubleArrayPhenotype) phenotype).getValues();
        double v = 0;

        int i = index;
        v += Math.cos(values[i] * 2 * Math.PI * 4.0) / (10.0 + values[i]);

        return v;
    }
}
